function [hd D] = HausdorffDist_par(P,Q,lmf)

sP = size(P); sQ = size(Q);

if ~(sP(2)==sQ(2))
    error('Inputs P and Q must have the same number of columns')
end

if nargin > 2 && ~isempty(lmf)
    % the user has specified the large matrix flag one way or the other
    largeMat = lmf;     
    if ~(largeMat==1 || largeMat==0)
        error('3rd ''lmf'' input must be 0 or 1')
    end
end

if largeMat
% we cannot save all distances, so loop through every point saving only
% those that are the best value so far

maxP = 0;            
parfor p = 1:sP(1)
    % calculate the minimum distance from points in P to Q
    minP(p) = min(sum( bsxfun(@minus,P(p,:),Q).^2, 2));
end
maxP=max(minP);


maxQ = 0;
% parfor q = 1:sQ(1)
%     minQ(q) = min(sum( bsxfun(@minus,Q(q,:),P).^2, 2));
% end
% maxQ=max(minQ);
hd = sqrt(max([maxP maxQ]));
D = [];
    
end




